package controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import pojo.User;
import service.Userservice;

@Controller
public class ZcController {
	@Resource
	private Userservice service;
	public void setService(Userservice service) {
		this.service = service;
	}
	public Userservice getService() {
		return service;
	}


	/**跳转到注册页面*/
	@RequestMapping(value="/zc",method=RequestMethod.GET)
	public String index() {
		return "zc";
	}
	
	/**用户注册*/
	@RequestMapping(value = "/zc",method = RequestMethod.POST)
	public String zc(@RequestParam String name,@RequestParam String pwd,HttpServletRequest request,
			HttpSession session) {
		User user = service.findname(name);
		if(null!=user) {
			request.setAttribute("msg", "用户名已存在");
			return "zc";
		}else {
			service.zc(name, pwd);
			request.setAttribute("msg", "注册成功");
			return "zc";
		}
	}

}
